﻿using System.Configuration;
using System.Text.RegularExpressions;

namespace Nana.Web.Compressing
{
  public class RegexElement
    : ConfigurationElement
  {
    internal RegexElement()
    {
    }

    public RegexElement(string name, string pattern, RegexOptions flags)
    {
      this.Name = name;
      this.Pattern = pattern;
      this.Flags = flags;
    }

    [ConfigurationProperty("name", IsRequired = true, IsKey = true, DefaultValue = "?")]
    [StringValidator(MinLength = 1)]
    public string Name
    {
      get
      {
        return this.GetConfig(c => c.Name);
      }
      set
      {
        this.SetConfig(c => c.Name, value);
      }
    }

    [ConfigurationProperty("pattern", IsRequired = true, DefaultValue = "??")]
    [StringValidator(MinLength = 2)]
    public string Pattern
    {
      get
      {
        return this.GetConfig(c => c.Pattern);
      }
      set
      {
        this.SetConfig(c => c.Pattern, value);
      }
    }

    [ConfigurationProperty("flags", DefaultValue = RegexOptions.ExplicitCapture)]
    public RegexOptions Flags
    {
      get
      {
        return this.GetConfig(c => c.Flags);
      }
      set
      {
        this.SetConfig(c => c.Flags, value);
      }
    }

  }
}
